package org.genko.model;

import org.w3c.dom.*;
/**
 * Defines the structure and rules of a MemberObject
 * @author Israel Chapa
 * 01/06/2010
 */
public interface MemberType
{
	/**
	 * Returns the name of this type
	 * @return The name of this MemberType
	 */
	String getTypeName();

	/**
	 * Returns the qualified name of this type
	 * @return The qualified name of this MemberType
	 */
	String getQualifiedName();

	/**
	 * Returns the model schema of this type
	 * @return The ModelSchema of this MemberType
	 */
	ModelSchema getSchema();

	/**
	 * Returns the base type of this type
	 * @return The Base MemberType of this MemberType
	 */
	MemberType getBaseType();

	/**
	 * Returns true if this type is a root type, which means that an instance of this type can be a root member in the model
	 * @return true if this type is a root type
	 */
	boolean isRootType();

	/**
	 * Returns true if this type is abstract
	 * @return true if this type is abstract, false otherwise
	 */
	boolean isAbstract();

	/**
	 * Returns true if this type is scalar
	 * @return true if this type is scalar, false otherwise
	 */
	boolean isScalar();

	/**
	 * Gets the implemented interfaces of this type
	 * @return The implemented interfaces of this MemberType
	 */
	MemberTypeCollection getInterfaces();

	/**
	 * Gets the member definitions of this type
	 * @return The member definitions of this MemberType
	 */
	Iterable<MemberDefinition> getMemberDefinitions();
	
	/**
	 * Gets the icon data for this type
	 * @return The icon data for this type
	 */
	byte[] getIcon();

	/**
	 * Gets the default name for a new instance object
	 * @param owner The future owner of the new instance, if any
	 * @return The default name for a new instance object
	 */
	String getDefaultMemberName(MemberObject owner);

	/**
	 * Returns true if this type is serializable
	 * @param instance The instance of this MemberType
	 * @return true if the given instance of this type is serializable, false otherwise
	 */
	boolean isSerializable(MemberObject instance);

	/**
	 * Indicates if the member instance can be renamed
	 * @param instance The object to test
	 * @param newName The new name to test
	 * @return true if the member can be renamed, false otherwise
	 */
	boolean allowRename(MemberObject instance, String newName);
	
	/**
	 * Returns true if the instance of this type is valid
	 * @return true if the instance of this MemberType is valid, false otherwise
	 */
	boolean isValid(MemberObject instance);
	
	/**
	 * Tests if the specified object is an attachable element to an instance of this Type
	 * @param testObject The object to test
	 * @return true if the given object is attachable element to an instance of this MemberType
	 */
	boolean isAttachable(MemberObject testObject);

	/**
	 * Tests if the specified object is dettachable element to an instance of this Type
	 * @param testObject The object to test
	 * @return true if the given object is dettachable element to an instance of this MemberType
	 */
	boolean isDetachable(MemberObject testObject);

	/**
	 * Returns all known element attachable types to the provided instance of this type
	 * @param instance The instance of this MemberType
	 * @return All known attachable types to the provided instance of this type
	 */
	MemberTypeCollection getAttachableTypes(MemberObject instance);

	/**
	 * Creates a new instance of this Type
	 * @return a new instance of this MemberType
	 */
	MemberObject newInstance();

	/**
	 * Returns the valid input value for the value set for the specified object
	 * @param instance The instance of this type
	 * @return The valid input value for the value set for the specified object
	 */
	String getInputValue(MemberObject instance);

	/**
	 * Sets the member object value from an input string
	 * @param instance The instance of this type
	 * @param input The input string
	 */
	void setInputValue(MemberObject instance, String input);

	/**
	 * Creates a new node based on this member object
	 * @param doc The document owner of the node
	 * @param instance The instance of this type
	 * @return The created node
	 */
	Node toXmlNode(Document doc, MemberObject instance);
}